// var app = getApp();
//md5
var CryptoJS = require("./tripledes.js");
CryptoJS = CryptoJS();
var decypt={
  decryptByDES: function (ciphertext, key) {
    
    var keyHex = CryptoJS.enc.Utf8.parse(key);

    // direct decrypt ciphertext
    var decrypted = CryptoJS.DES.decrypt({
      ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
    }, keyHex, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
      });

    return decrypted.toString(CryptoJS.enc.Utf8);
  },
  renderVideo:function (videoData) {
    String.prototype.startWith = function (str) {
      var reg = new RegExp("^" + str);
      return reg.test(this);
    }
    var videoUrl = videoData;
    /*判断是否http开头，不是则解密*/
    if (videoUrl != undefined && videoUrl.startWith('http') == false) {
      var key = 'www.chuangchuang.cn';
      var enUrl = videoUrl.replace(/[\r\n]/g, "");
      videoUrl = this.decryptByDES(enUrl, key);
    }
    console.log(videoUrl)
    return videoUrl

  }

}
module.exports = decypt;
